package lwk.juc.sup;

import java.util.concurrent.CyclicBarrier;

/**
 * @author:lwk
 * @create: 2022-08-13 10:09
 */
public class TestCyclicBarrier {

    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7, () -> System.out.println("成功集齐七颗龙珠，召唤神龙~~"));

        for (int i = 1; i <= 7; i++) {
            final int tempI = i;
            new Thread(()->{
                System.out.println("找到了"+tempI+"星球！！");
                try {
                    cyclicBarrier.await();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }).start();
        }

        System.out.println("-------- main end ------");
    }

}
